﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Common
{
   public class ValidateHelper
    {
       /// <summary>
       /// 手机号验证
       /// </summary>
       /// <param name="src">手机号</param>
       /// <returns></returns>
       public static bool IsMobile(string src)
       {
           if (string.IsNullOrEmpty(src))
           {
               return false;
           }
           return RegexHelper.IsMatch(src, @"^((1[3|5|8][0-9])|(14[5|7])|(17[0|6|7|8]))\d{8}$");
       }
       /// <summary>
       /// 邮箱验证
       /// </summary>
       /// <param name="src">邮箱</param>
       /// <returns></returns>
       public static bool IsEmail(string src)
       {
           if (string.IsNullOrEmpty(src))
           {
               return false;
           }
           return RegexHelper.IsMatch(src, @"^[\d\w]{1,30}@[\d\w]{1,10}\.[\d\w]{1,5}$");
       }
       /// <summary>
       /// 长度验证
       /// </summary>
       /// <param name="src">字符串</param>
       /// <param name="min">最小长度默认6</param>
       /// <param name="max">最大长度默认长度30</param>
       /// <returns></returns>
       public static bool IsLen(string src,int min=6, int max=30)
       {
           if (string.IsNullOrEmpty(src))
           {
               return false;
           }
           return src.Length > 6 && src.Length < 30;
       }
       /// <summary>
       /// 身份证简单验证
       /// </summary>
       /// <param name="src">身份证验证</param>
       /// <returns></returns>
       public static bool IsIDNumber(string src)
       {
           if(string.IsNullOrEmpty(src))
           {
               return false;
           }
           return RegexHelper.IsMatch(src,@"^(^\d{15}$|^\d{17}(\d|X|x))$");
       }
       /// <summary>
       /// 判断一个数的范围
       /// </summary>
       /// <param name="src">要判断的数</param>
       /// <param name="min">最小值</param>
       /// <param name="max">最大值</param>
       /// <returns></returns>
       public static bool IsRange(int src,int min, int max)
       {
           
               return min<max?src > min && src < max:src > max && src < min;
           
       }
    }
}
